package com.bawei.yangzongcai___chenmei.MaiuActivity;


import android.content.Intent;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import com.bawei.yangzongcai___chenmei.Adpter.FragementOne;
import com.bawei.yangzongcai___chenmei.BlankFragment.Blanck1.BlankFragmentZhu1;
import com.bawei.yangzongcai___chenmei.BlankFragment.Blanck1.BlankFragmentZhu2;
import com.bawei.yangzongcai___chenmei.BlankFragment.Blanck1.BlankFragmentZhu3;
import com.bawei.yangzongcai___chenmei.BlankFragment.Blanck1.BlankFragmentZhu4;
import com.bawei.yangzongcai___chenmei.BlankFragment.Blanck1.BlankFragmentZhu5;
import com.bawei.yangzongcai___chenmei.BlankFragment.Blanck1.BlankFragmentZhu6;
import com.bawei.yangzongcai___chenmei.MVC.BsaeActivity;
import com.bawei.yangzongcai___chenmei.R;
import com.bawei.yangzongcai___chenmei.Service.MyServiceActivity;
import com.bawei.yangzongcai___chenmei.SlindingMenu.SlingMenuActivity1;
import com.bawei.yangzongcai___chenmei.SlindingMenu.SlingMenuActivity2;
import com.bawei.yangzongcai___chenmei.SlindingMenu.SlingMenuActivity3;
import com.bawei.yangzongcai___chenmei.SlindingMenu.SlingMenuActivity4;
import com.bawei.yangzongcai___chenmei.SlindingMenu.SlingMenuActivity5;
import com.bawei.yangzongcai___chenmei.SlindingMenu.SlingMenuActivity6;
import com.bawei.yangzongcai___chenmei.SlindingMenu.SlingMenuActivity7;
import com.blankj.utilcode.util.ToastUtils;
import com.frame.lib_common.slidingmenu.SlidingMenu;

import java.util.ArrayList;

public class MainActivity extends BsaeActivity  {

    private ViewPager main1Vp;
    private RadioGroup main1Rg;
    private RadioButton main1B1;
    private RadioButton main1B2;
    private RadioButton main1B3;
    private RadioButton main1B4;
    private RadioButton main1B5;
    private RadioButton main1B6;
    private SlidingMenu slidingMenu;
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_DOWN) {
            long secondTime = System.currentTimeMillis();
            long firstTime =0;
            if (secondTime - firstTime > 2000) {
                Toast.makeText(MainActivity.this, "再按一次退出程序", Toast.LENGTH_SHORT).show();
                firstTime = secondTime;
                return true;
            } else{
                finish();
            }
        }
        return super.onKeyDown(keyCode, event);
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu,menu);
        return super.onCreateOptionsMenu(menu);
    }

    @Override
    public boolean onOptionsItemSelected(@NonNull MenuItem item) {
        switch (item.getItemId())
        {
            case R.id.tiananmen:
                ToastUtils.showShort("天安门广场");
                break;

            case R.id.renming:
                ToastUtils.showShort("人民大会堂");
                break;

            case R.id.bowuguan:
                ToastUtils.showShort("军事博物馆");
                break;
        }
        return super.onOptionsItemSelected(item);
    }

    @Override
    public int bandLayout() {
        return R.layout.activity_main;
    }

    @Override
    public void initView() {
        main1Vp = findViewById(R.id.main1_vp);
        main1Rg = findViewById(R.id.main1_rg);
        main1B1 = findViewById(R.id.main1_b1);
        main1B2 = findViewById(R.id.main1_b2);
        main1B3 = findViewById(R.id.main1_b3);
        main1B4 = findViewById(R.id.main1_b4);
        main1B5 = findViewById(R.id.main1_b5);
        main1B6 = findViewById(R.id.main1_b6);
    }



    @Override
    public void initDate() {

        ArrayList<Fragment> fragments = new ArrayList<>();
        fragments.add(new BlankFragmentZhu5());
        fragments.add(new BlankFragmentZhu2());
        fragments.add(new BlankFragmentZhu3());
        fragments.add(new BlankFragmentZhu4());
        fragments.add(new BlankFragmentZhu1());
        fragments.add(new BlankFragmentZhu6());

        FragementOne fragementOne = new FragementOne(getSupportFragmentManager(),fragments);
        main1Vp.setAdapter(fragementOne);

        main1Rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                switch (checkedId)
                {
                    case R.id.main1_b1:
                        main1Vp.setCurrentItem(0);
                        break;

                    case R.id.main1_b2:
                        main1Vp.setCurrentItem(1);
                        break;

                    case R.id.main1_b3:
                        main1Vp.setCurrentItem(2);
                        break;

                    case R.id.main1_b4:
                        main1Vp.setCurrentItem(3);
                        break;

                    case R.id.main1_b5:
                        main1Vp.setCurrentItem(4);
                        break;

                    case R.id.main1_b6:
                        main1Vp.setCurrentItem(5);
                        break;
                }
            }
        });



        //-----------------------侧拉-----------------------
        slidingMenu = new SlidingMenu(this);
        slidingMenu.attachToActivity(this,SlidingMenu.SLIDING_CONTENT);
        slidingMenu.setMode(SlidingMenu.LEFT);
        slidingMenu.setMenu(R.layout.slidingmenulayout);
        slidingMenu.setBehindWidth(1000);
        slidingMenu.showContent();


        View menu = slidingMenu.getMenu();
        menu.findViewById(R.id.sling___gong1).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ToastUtils.showShort("按钮1");
                Intent intent = new Intent(MainActivity.this, SlingMenuActivity1.class);
                startActivity(intent);
            }
        });


        menu.findViewById(R.id.sling___gong2).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ToastUtils.showShort("按钮2");
                Intent intent = new Intent(MainActivity.this, SlingMenuActivity2.class);
                startActivity(intent);
            }
        });


        menu.findViewById(R.id.sling___gong3).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ToastUtils.showShort("按钮三");
                Intent intent = new Intent(MainActivity.this, SlingMenuActivity3.class);
                startActivity(intent);
            }
        });

        menu.findViewById(R.id.sling___gong4).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ToastUtils.showShort("按钮四");
                Intent intent = new Intent(MainActivity.this, SlingMenuActivity4.class);
                startActivity(intent);
            }
        });

        menu.findViewById(R.id.sling___gong5).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ToastUtils.showShort("按钮五");
                Intent intent = new Intent(MainActivity.this, SlingMenuActivity5.class);
                startActivity(intent);
            }
        });


        menu.findViewById(R.id.sling___gong6).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ToastUtils.showShort("按钮六");
                Intent intent = new Intent(MainActivity.this, SlingMenuActivity6.class);
                startActivity(intent);
            }
        });


        menu.findViewById(R.id.sling___gong7).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ToastUtils.showShort("按钮七");
                Intent intent = new Intent(MainActivity.this, SlingMenuActivity7.class);
                startActivity(intent);
            }
        });


        menu.findViewById(R.id.sling___gong8).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ToastUtils.showShort("主页面2号");
                Intent intent = new Intent(MainActivity.this,MainActivity2.class);
                startActivity(intent);
            }
        });


        menu.findViewById(R.id.sling___gong9).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ToastUtils.showShort("音乐");
                Intent intent = new Intent(MainActivity.this, MyServiceActivity.class);
                startActivity(intent);

            }
        });


        menu.findViewById(R.id.sling___gong10).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ToastUtils.showShort("按钮8");

            }
        });

        menu.findViewById(R.id.sling___gong11).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ToastUtils.showShort("按钮9");

            }
        });

        menu.findViewById(R.id.sling___gong12).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ToastUtils.showShort("按钮10");
            }
        });

        menu.findViewById(R.id.sling___gong13).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ToastUtils.showShort("按钮11");
            }
        });



    }
}
